from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2023-01-06 14:03:05.281432
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Fri, 06, Jan, 2023
Time: 14:03:14
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -51.3610
Nobs: 893.000 HQIC: -51.6595
Log likelihood: 11834.4 FPE: 3.05041e-23
AIC: -51.8442 Det(Omega_mle): 2.75950e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.293403 0.049010 5.987 0.000
L1.Burgenland 0.106756 0.033758 3.162 0.002
L1.Kärnten -0.106210 0.018109 -5.865 0.000
L1.Niederösterreich 0.215178 0.070809 3.039 0.002
L1.Oberösterreich 0.077354 0.066887 1.156 0.247
L1.Salzburg 0.249344 0.035866 6.952 0.000
L1.Steiermark 0.031514 0.047030 0.670 0.503
L1.Tirol 0.126332 0.038175 3.309 0.001
L1.Vorarlberg -0.059112 0.032872 -1.798 0.072
L1.Wien 0.069381 0.059661 1.163 0.245
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.061201 0.100452 0.609 0.542
L1.Burgenland -0.009735 0.069191 -0.141 0.888
L1.Kärnten 0.048828 0.037117 1.316 0.188
L1.Niederösterreich -0.170580 0.145131 -1.175 0.240
L1.Oberösterreich 0.359787 0.137093 2.624 0.009
L1.Salzburg 0.285697 0.073510 3.886 0.000
L1.Steiermark 0.106951 0.096392 1.110 0.267
L1.Tirol 0.320664 0.078244 4.098 0.000
L1.Vorarlberg 0.025447 0.067375 0.378 0.706
L1.Wien -0.022507 0.122282 -0.184 0.854
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.201109 0.025548 7.872 0.000
L1.Burgenland 0.090873 0.017597 5.164 0.000
L1.Kärnten -0.008682 0.009440 -0.920 0.358
L1.Niederösterreich 0.267403 0.036911 7.245 0.000
L1.Oberösterreich 0.108108 0.034866 3.101 0.002
L1.Salzburg 0.053039 0.018696 2.837 0.005
L1.Steiermark 0.016141 0.024515 0.658 0.510
L1.Tirol 0.101046 0.019900 5.078 0.000
L1.Vorarlberg 0.058140 0.017135 3.393 0.001
L1.Wien 0.113709 0.031100 3.656 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.107129 0.026224 4.085 0.000
L1.Burgenland 0.048376 0.018063 2.678 0.007
L1.Kärnten -0.015835 0.009690 -1.634 0.102
L1.Niederösterreich 0.197827 0.037887 5.221 0.000
L1.Oberösterreich 0.274580 0.035789 7.672 0.000
L1.Salzburg 0.117285 0.019190 6.112 0.000
L1.Steiermark 0.100987 0.025164 4.013 0.000
L1.Tirol 0.123537 0.020426 6.048 0.000
L1.Vorarlberg 0.070917 0.017589 4.032 0.000
L1.Wien -0.025645 0.031922 -0.803 0.422
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.132806 0.047084 2.821 0.005
L1.Burgenland -0.052608 0.032431 -1.622 0.105
L1.Kärnten -0.035448 0.017398 -2.038 0.042
L1.Niederösterreich 0.167314 0.068026 2.460 0.014
L1.Oberösterreich 0.127976 0.064258 1.992 0.046
L1.Salzburg 0.289770 0.034456 8.410 0.000
L1.Steiermark 0.035741 0.045181 0.791 0.429
L1.Tirol 0.157275 0.036675 4.288 0.000
L1.Vorarlberg 0.109972 0.031580 3.482 0.000
L1.Wien 0.068678 0.057316 1.198 0.231
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.064461 0.037478 1.720 0.085
L1.Burgenland 0.038379 0.025814 1.487 0.137
L1.Kärnten 0.049742 0.013848 3.592 0.000
L1.Niederösterreich 0.226317 0.054147 4.180 0.000
L1.Oberösterreich 0.263651 0.051148 5.155 0.000
L1.Salzburg 0.059796 0.027426 2.180 0.029
L1.Steiermark -0.006343 0.035963 -0.176 0.860
L1.Tirol 0.158341 0.029192 5.424 0.000
L1.Vorarlberg 0.069153 0.025137 2.751 0.006
L1.Wien 0.077160 0.045622 1.691 0.091
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.193950 0.045195 4.291 0.000
L1.Burgenland 0.017385 0.031130 0.558 0.577
L1.Kärnten -0.057135 0.016700 -3.421 0.001
L1.Niederösterreich -0.096021 0.065297 -1.471 0.141
L1.Oberösterreich 0.175204 0.061680 2.841 0.005
L1.Salzburg 0.060903 0.033074 1.841 0.066
L1.Steiermark 0.224423 0.043369 5.175 0.000
L1.Tirol 0.478867 0.035203 13.603 0.000
L1.Vorarlberg 0.053007 0.030313 1.749 0.080
L1.Wien -0.048851 0.055017 -0.888 0.375
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.153213 0.050788 3.017 0.003
L1.Burgenland -0.000767 0.034982 -0.022 0.983
L1.Kärnten 0.067338 0.018766 3.588 0.000
L1.Niederösterreich 0.202402 0.073377 2.758 0.006
L1.Oberösterreich -0.071136 0.069313 -1.026 0.305
L1.Salzburg 0.220368 0.037166 5.929 0.000
L1.Steiermark 0.107991 0.048735 2.216 0.027
L1.Tirol 0.083326 0.039559 2.106 0.035
L1.Vorarlberg 0.128267 0.034064 3.765 0.000
L1.Wien 0.110141 0.061825 1.782 0.075
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.355960 0.030130 11.814 0.000
L1.Burgenland 0.008861 0.020754 0.427 0.669
L1.Kärnten -0.024936 0.011133 -2.240 0.025
L1.Niederösterreich 0.230441 0.043532 5.294 0.000
L1.Oberösterreich 0.147483 0.041121 3.587 0.000
L1.Salzburg 0.052060 0.022049 2.361 0.018
L1.Steiermark -0.016002 0.028913 -0.553 0.580
L1.Tirol 0.120532 0.023469 5.136 0.000
L1.Vorarlberg 0.074413 0.020209 3.682 0.000
L1.Wien 0.052468 0.036678 1.430 0.153
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.039442 0.167267 0.185638 0.172846 0.149890 0.132127 0.069832 0.223301
Kärnten 0.039442 1.000000 0.003380 0.132274 0.027463 0.099538 0.428027 -0.048048 0.101964
Niederösterreich 0.167267 0.003380 1.000000 0.355016 0.177539 0.323306 0.141544 0.196595 0.346227
Oberösterreich 0.185638 0.132274 0.355016 1.000000 0.241323 0.348931 0.192566 0.183309 0.277806
Salzburg 0.172846 0.027463 0.177539 0.241323 1.000000 0.160164 0.145415 0.155626 0.145243
Steiermark 0.149890 0.099538 0.323306 0.348931 0.160164 1.000000 0.170487 0.152144 0.102743
Tirol 0.132127 0.428027 0.141544 0.192566 0.145415 0.170487 1.000000 0.128728 0.169553
Vorarlberg 0.069832 -0.048048 0.196595 0.183309 0.155626 0.152144 0.128728 1.000000 0.024258
Wien 0.223301 0.101964 0.346227 0.277806 0.145243 0.102743 0.169553 0.024258 1.000000